const http = require('http');

// 创建HTTP服务器
const server = http.createServer((req, res) => {
  // 设置响应的头部
  res.setHeader('Content-Type', 'text/html; charset=utf-8');

  // 检查URL并设置HTML响应的内容
  if (req.url === '/') {
    res.write('<h1>Welcome to our Website</h1>');
  } else if (req.url === '/about') {
    res.write('<h1>About Us</h1>');
  } else if (req.url === '/contact') {
    res.write('<h1>Contact Us</h1>');
  } else {
    res.writeHead(404); // Set status to 404
    res.write('<h1>404 - The page you requested is not available</h1>');
  }

  // 结束响应 - 如果不调用这个函数，客户端将不会接收到完整的响应
  res.end();
});

// 开始监听80端口
server.listen(80, () => {
  console.log('Server is listening on port 80');
});